package com.xinxing.learning.datasource.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinxing.learning.datasource.annotation.DataSourceRoute;
import com.xinxing.learning.datasource.mapper.TestUserMapper;
import com.xinxing.learning.datasource.model.TestUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TestUserService {

    @Autowired
    private TestUserMapper testUserMapper;


    /**
     * 查询master库User
     *
     * @return
     */
    @DataSourceRoute(value = "master")
    public List<TestUser> getMasterUser() {
        QueryWrapper<TestUser> queryWrapper = new QueryWrapper<>();
        return testUserMapper.selectAll();
    }

    /**
     * 查询slave库User
     *
     * @return
     */
    @DataSourceRoute(value = "slave")
    public List<TestUser> getSlaveUser() {
        return testUserMapper.selectList(null);
    }

    public List<TestUser> getUser() {
        return testUserMapper.selectList(null);
    }
}